package cn.easybuy.ajax;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.easybuy.biz.Easybuy_UserBiz;
import cn.easybuy.biz.Impl.Easybuy_UserBizImpl;
import cn.easybuy.entity.Easybuy_User;

public class AjaxZhuc extends HttpServlet {
	String hint;
	String status;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		Easybuy_UserBiz easybuy_UserBiz = new Easybuy_UserBizImpl();

		PrintWriter out = response.getWriter();
		String opr = request.getParameter("opr");
		System.out.println(opr);
		if ("name".equals(opr)) {
			String user = request.getParameter("l_user");
			Easybuy_User easybuy_User = easybuy_UserBiz.getAllLoginName(user);
			if (easybuy_User == null) {
				status = "success";
				hint = "用户可以注册";
			} else {
				status = "erorr";
				hint = "用户名不可以注册";
			}
			out.print("[{\"hint\":\"" + hint + "\",\"status\":\"" + status
					+ "\"}]");
			out.flush();
			out.close();
		} else if ("pwd".equals(opr)) {
			String user = request.getParameter("l_user");
			Easybuy_User easybuy_User = easybuy_UserBiz.getAllLoginName(user);
			if (easybuy_User == null) {
				status = "error";
				hint = "用户名不存在";
			} else {
				status = "success";
				hint = "用户名可用";
			}
			out.print("[{\"hint\":\"" + hint + "\",\"status\":\"" + status
					+ "\"}]");
			out.flush();
			out.close();
		} else if ("pwd1".equals(opr)) {
			String pwd2 = request.getParameter("l_pwd");
			String user = request.getParameter("l_user");
			Easybuy_User easybuy_User = easybuy_UserBiz.getUserPassword(user,
					pwd2);
			if (easybuy_User != null) {
				status = "success";
				hint = "密码正确";
			} else {
				status = "error";
				hint = "密码不正确";
			}
			out.print("[{\"hint\":\"" + hint + "\",\"status\":\"" + status
					+ "\"}]");
			out.flush();
			out.close();
		}

	}
}
